OpenXava doesn't include internal mechanism for supporting Spring beans injection into IAction, ICalculator and other OX front-end implementors, but still by using Spring AOP in combination with AspectJ, it is possible to inject beans (e.g. beans from service layer - services) into OX dependent classes.
Dependencies
The next several jar dependencies must be included within OpenXava/web/WEB-INF/lib directory in order to use Spring features:
spring-core.jar,
spring-beans.jar,
spring-context.jar and
spring-aspects.jar.
For load-time weaving purposes, these AspectJ libraries are required:
aspectjrt.jar and
aspectjweaver.jar
They should be also located within OpenXava/web/WEB-INF/lib directory.
Additional dependency is spring-agent.jar which will be passed externally to the JVM. Note: In the time when this tutorial has been written, the actual version of Spring jars was 2.5.6 and for AspectJ jars it was 1.6.1.
Application context
In order to initialize Spring application context, few lines must be added into the OpenXava/web/WEB-INF/web.xml file, like in the example bellow:
Note: For more information on this, please check Spring Reference.
Load-time weaving with AspectJ
Load-time weaving (LTW) is simply binary weaving defered until the point that a class loader loads a class file and defines the class to the JVM. To support this, one or more "weaving class loaders", either provided explicitly by the run-time environment or enabled through a "weaving agent" are required. For this purpose Spring agent must be used and specified on the JVM startup, like in the example bellow:
java -javaagent:path/to/spring-agent.jar
Note: If you're using Tomcat application server, javaagent option can be specified through JAVA_OPTS parameter and the logical place for spring-agent.jar could be ${catalina.home}/server/lib.
Java annotation driven injection
Spring context module provides additional configuration through Java annotations so an application context XML might look like the example bellow:
Each time when OpenXava instances ExampleAction class, LTW mechanism will listen for such event and set additional bean dependencies from the application context. Note: Please refer to Spring Reference and AspectJ Guide for more information about LTW and annotation based configuration.
Table of Contents
Spring
OpenXava doesn't include internal mechanism for supporting Spring beans injection into IAction, ICalculator and other OX front-end implementors, but still by using Spring AOP in combination with AspectJ, it is possible to inject beans (e.g. beans from service layer - services) into OX dependent classes.Dependencies
The next several jar dependencies must be included within OpenXava/web/WEB-INF/lib directory in order to use Spring features:- spring-core.jar,
- spring-beans.jar,
- spring-context.jar and
- spring-aspects.jar.
For load-time weaving purposes, these AspectJ libraries are required:- aspectjrt.jar and
- aspectjweaver.jar
They should be also located within OpenXava/web/WEB-INF/lib directory.Additional dependency is spring-agent.jar which will be passed externally to the JVM.
Note: In the time when this tutorial has been written, the actual version of Spring jars was 2.5.6 and for AspectJ jars it was 1.6.1.
Application context
In order to initialize Spring application context, few lines must be added into the OpenXava/web/WEB-INF/web.xml file, like in the example bellow:Note: For more information on this, please check Spring Reference.
Load-time weaving with AspectJ
Load-time weaving (LTW) is simply binary weaving defered until the point that a class loader loads a class file and defines the class to the JVM. To support this, one or more "weaving class loaders", either provided explicitly by the run-time environment or enabled through a "weaving agent" are required. For this purpose Spring agent must be used and specified on the JVM startup, like in the example bellow:Note: If you're using Tomcat application server, javaagent option can be specified through JAVA_OPTS parameter and the logical place for spring-agent.jar could be ${catalina.home}/server/lib.
Java annotation driven injection
Spring context module provides additional configuration through Java annotations so an application context XML might look like the example bellow:When application context is configured like that, an action implementation that uses exampleService bean, might look like in the following example:
Each time when OpenXava instances ExampleAction class, LTW mechanism will listen for such event and set additional bean dependencies from the application context.
Note: Please refer to Spring Reference and AspectJ Guide for more information about LTW and annotation based configuration.